using Godot;
using System;
using System.Collections.Generic;

public partial class RandomStreamPlayer2dComponent : AudioStreamPlayer2D
{
	[Export]
	public AudioStream[] streams;
	[Export]
	bool randomizePitch = true;
	[Export]
	double minPitch = .9;
	[Export]
	double maxPitch = 1.1;
	
	 
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void PlayRandom(){
		if(streams == null || streams.Length == 0){
			return;
		}
		Random random = new Random();
		if(randomizePitch){
			PitchScale = (float)(random.NextDouble() * (maxPitch - minPitch) + minPitch);
		}else{
			PitchScale = 1;
		}
		Stream = streams[random.Next(0,streams.Length)];
		Play();
	}
}
